from django .shortcuts import render #line:2
from django .http import HttpResponse #line:3
from django .http import JsonResponse #line:4
from django .views .decorators .csrf import csrf_exempt #line:5
import os #line:6
from py2neo import Graph ,Node ,Relationship #line:7
import json #line:8
import configparser #line:9
from .import login_required #line:10
cf =configparser .ConfigParser ()#line:11
cf .read ("./kg.conf")#line:12
def index (OOOO0O000OOO0OOOO ):#line:19
    O0O0OO0O0O0OOO000 ={}#line:20
    return render (OOOO0O000OOO0OOOO ,"graph_math.html",{'ctx':O0O0OO0O0O0OOO000 })#line:22
@csrf_exempt #line:24
def pankrange_math (OO00O0OO0000000OO ):#line:25
  OO0O00000OOO0OO00 =OO00O0OO0000000OO .POST ['retype']#line:26
  if len (OO0O00000OOO0OO00 )==0 :#line:27
    O0O00OOO0OOOO00OO ={"error":'关系类型不能为空'}#line:28
    return HttpResponse (json .dumps (O0O00OOO0OOOO00OO ),content_type ="application/json")#line:29
  OO0OO0OOO0OOO0O00 =cf .get ("neo4j","url")#line:30
  OOO0000OOO0O0OOO0 =cf .get ("neo4j","username")#line:31
  O00000OOOOOOOO0OO =cf .get ("neo4j","password")#line:32
  OO000O000OO000OO0 =Graph (OO0OO0OOO0OOO0O00 ,auth =(OOO0000OOO0O0OOO0 ,O00000OOOOOOOO0OO ))#line:33
  O000O0O0000OO0000 =''#line:34
  if OO0O00000OOO0OO00 =='不限关系':#line:35
    O000O0O0000OO0000 ='''CALL algo.pageRank(
    'MATCH (p) RETURN id(p) as id',
    'MATCH (p1)-[r]-(p2) RETURN id(p1) as source, id(p2) as target',
    {graph:'cypher', iterations:20, write: true,writeProperty:'pagerank_不限关系'})'''#line:39
  else :#line:40
    O000O0O0000OO0000 ='CALL algo.pageRank(\'MATCH (p) RETURN id(p) as id\',\'MATCH (p1)-[r:'+OO0O00000OOO0OO00 +']-(p2) RETURN id(p1) as source, id(p2) as target\', {graph:\'cypher\', iterations:20, write: true,writeProperty:\''+'pagerank_'+OO0O00000OOO0OO00 +'\'})'#line:41
  print (O000O0O0000OO0000 )#line:42
  OO00OO0O0O0OO000O =OO000O000OO000OO0 .run (O000O0O0000OO0000 )#line:43
  O0O00OOO0OOOO00OO ={'执行详情':str (OO00OO0O0O0OO000O )}#line:44
  return HttpResponse (json .dumps (O0O00OOO0OOOO00OO ),content_type ="application/json")#line:45
@csrf_exempt #line:48
def group_math (OOO00OO00O000OOOO ):#line:49
  O000OOO0OO00OO00O =OOO00OO00O000OOOO .POST ['retype']#line:50
  if len (O000OOO0OO00OO00O )==0 :#line:51
    O0OO0000O0O0OO0O0 ={"error":'关系类型不能为空'}#line:52
    return HttpResponse (json .dumps (O0OO0000O0O0OO0O0 ),content_type ="application/json")#line:53
  OO0O0000OO0O000O0 =cf .get ("neo4j","url")#line:54
  OOOOO0OO0OO0OO000 =cf .get ("neo4j","username")#line:55
  OO0O0O0OOOOOO00O0 =cf .get ("neo4j","password")#line:56
  O0O0OOO0O00OO0OOO =Graph (OO0O0000OO0O000O0 ,auth =(OOOOO0OO0OO0OO000 ,OO0O0O0OOOOOO00O0 ))#line:57
  OOO00O0O000O00O0O =''#line:58
  if O000OOO0OO00OO00O =='不限关系':#line:59
    OOO00O0O000O00O0O ='''
  CALL algo.labelPropagation('', '',
  {iterations: 10, writeProperty: 'community_不限关系', write: true, direction: 'OUTGOING'}) '''#line:62
  else :#line:63
    OOO00O0O000O00O0O ='CALL algo.labelPropagation(\'\', \''+O000OOO0OO00OO00O +'\',{iterations: 10, writeProperty: \''+'community_'+O000OOO0OO00OO00O +'\', write: true, direction: \'OUTGOING\'})'#line:64
  print (OOO00O0O000O00O0O )#line:65
  OOOOOOOO0OO0OOO00 =O0O0OOO0O00OO0OOO .run (OOO00O0O000O00O0O )#line:66
  O0OO0000O0O0OO0O0 ={'执行详情':str (OOOOOOOO0OO0OOO00 )}#line:67
  return HttpResponse (json .dumps (O0OO0000O0O0OO0O0 ),content_type ="application/json")#line:68
@csrf_exempt #line:71
def get_lable_re_math (O00OOOO0OOO000000 ):#line:72
  O0O00OOO0000O0O0O =cf .get ("neo4j","url")#line:73
  OOO0OOOOOO0OOO0O0 =cf .get ("neo4j","username")#line:74
  OOOO000OO000000OO =cf .get ("neo4j","password")#line:75
  O0O0OOO0OOOOO00OO =Graph (O0O00OOO0000O0O0O ,auth =(OOO0OOOOOO0OOO0O0 ,OOOO000OO000000OO ))#line:76
  OO0000O0O000O00O0 =O0O0OOO0OOOOO00OO .run ("call db.labels").data ()#line:78
  O00OO000O000000O0 =O0O0OOO0OOOOO00OO .run ("call db.relationshipTypes").data ()#line:80
  O0O000O00OO0OOOOO ={"labelsret":OO0000O0O000O00O0 ,'relationshiptypesret':O00OO000O000000O0 }#line:82
  return HttpResponse (json .dumps (O0O000O00OO0OOOOO ),content_type ="application/json")#line:83
@csrf_exempt #line:87
def getgrouplist (OO0OO0OO0OO0OOOO0 ):#line:88
  O00000OO00OO000OO =OO0OO0OO0OO0OOOO0 .POST ['groupkey']#line:89
  if len (O00000OO00OO000OO )==0 :#line:90
    OO0O000O0OOOOO0OO ={"error":'groupkey不能为空'}#line:91
    return HttpResponse (json .dumps (OO0O000O0OOOOO0OO ),content_type ="application/json")#line:92
  O00O0OO0OOOO000O0 =cf .get ("neo4j","url")#line:93
  OO000OO00OOO0000O =cf .get ("neo4j","username")#line:94
  O0OO00O0OO0OO00O0 =cf .get ("neo4j","password")#line:95
  OO0O000O00O0OO00O =Graph (O00O0OO0OOOO000O0 ,auth =(OO000OO00OOO0000O ,O0OO00O0OO0OO00O0 ))#line:96
  OO0O000O0000OOO0O ='match(n) where EXISTS(n.`'+O00000OO00OO000OO +'`) return distinct n.'+O00000OO00OO000OO +', count(n) order by  count(n) desc limit 50'#line:97
  OOOO000O000000000 =OO0O000O00O0OO00O .run (OO0O000O0000OOO0O )#line:98
  OO0O000O0OOOOO0OO =[]#line:99
  for O0OOO0OOO00000O0O in OOOO000O000000000 :#line:100
    OO0O000O0OOOOO0OO .append ({'grouptype':O00000OO00OO000OO ,'groupid':O0OOO0OOO00000O0O [0 ],'groupcount':O0OOO0OOO00000O0O [1 ]})#line:101
  return HttpResponse (json .dumps ({'data':OO0O000O0OOOOO0OO }),content_type ="application/json")#line:102
@csrf_exempt #line:106
def getpglist (O00000OO0000OOOOO ):#line:107
  O0O00O00OO00000O0 =O00000OO0000OOOOO .POST ['pgkey']#line:108
  if len (O0O00O00OO00000O0 )==0 :#line:109
    OOOO0000OOOOO0OOO ={"error":'pgkey不能为空'}#line:110
    return HttpResponse (json .dumps (OOOO0000OOOOO0OOO ),content_type ="application/json")#line:111
  OO00O0O00OOOOO00O =cf .get ("neo4j","url")#line:112
  O000O00OO0OOOO0O0 =cf .get ("neo4j","username")#line:113
  OOOOO00000OOOOO00 =cf .get ("neo4j","password")#line:114
  O0OOOO0OOOOO0O00O =Graph (OO00O0O00OOOOO00O ,auth =(O000O00OO0OOOO0O0 ,OOOOO00000OOOOO00 ))#line:115
  OO0O0O0OO0OO00O0O ='match(n) where EXISTS(n.'+O0O00O00OO00000O0 +') return n.label, n.name,n.'+O0O00O00OO00000O0 +'  order by  n.'+O0O00O00OO00000O0 +' desc limit 50'#line:116
  OO00OOO0OO0OO0O00 =O0OOOO0OOOOO0O00O .run (OO0O0O0OO0OO00O0O )#line:117
  OOOO0000OOOOO0OOO =[]#line:118
  for OOO0OO0OO00OOO0OO in OO00OOO0OO0OO0O00 :#line:119
    OOOO0000OOOOO0OOO .append ({'pgtype':OOO0OO0OO00OOO0OO [0 ],'pgname':OOO0OO0OO00OOO0OO [1 ],'pgweight':OOO0OO0OO00OOO0OO [2 ]})#line:120
  return HttpResponse (json .dumps ({'data':OOOO0000OOOOO0OOO }),content_type ="application/json")#line:121
